package com.gu.controller;

import com.gu.entity.CrmBanner;
import com.gu.service.CrmBannerService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description: 首页轮播图效果 不经常改变，但是需要大量访问，所以此处需要映入 redis缓存
 *
 * @Autor: Rolin
 * datetime: 05-30-22:29
 */
@RestController
@CrossOrigin
@Api(tags = "轮播图插图前台显示系统")
@RequestMapping("/serviceCms")
public class FrontBannerController {

    @Resource
    private CrmBannerService crmBannerService;

    @ApiOperation("查询出所有的轮播图片")
    @GetMapping("/getAllBanners")
    // redis 缓存有的则是直接查询 缓存 ，否则查数据库并且保存到缓存当中；
    @Cacheable(value = "banner",key = "'selectIndexList'")
    public CommonResult getAllBanners(){

        List<CrmBanner> crmBanners = crmBannerService.getAll();
        return crmBanners.size()>0 ? CommonResult.success().data("bannerList",crmBanners):CommonResult.error();
    }
}
